---
# Copyright 2025, Cleura AB
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

systemd_interface_cleanup: true

aio_systemd_networkd_devices_bootstrap:
  - NetDev:
      Name: dummy-mgmt
      Kind: dummy
  - NetDev:
      Name: br-mgmt
      Kind: bridge

  - NetDev:
      Name: dummy-vxlan
      Kind: dummy
  - NetDev:
      Name: br-vxlan
      Kind: bridge

  - NetDev:
      Name: dummy-storage
      Kind: dummy
  - NetDev:
      Name: br-storage
      Kind: bridge

  - NetDev:
      Name: dummy-vlan
      Kind: dummy
  - NetDev:
      Name: br-vlan
      Kind: bridge
  - NetDev:
      Name: br-vlan-veth
      Kind: veth
    Peer:
      Name: eth12
{% if 'trove' in bootstrap_host_scenarios_expanded %}
  - NetDev:
      Name: dummy-dbaas
      Kind: dummy
  - NetDev:
      Name: br-dbaas
      Kind: bridge
  - NetDev:
      Name: br-dbaas-veth
      Kind: veth
    Peer:
      Name: eth13
{% endif %}
{% if 'octavia' in bootstrap_host_scenarios_expanded %}
  - NetDev:
      Name: dummy-lbaas
      Kind: dummy
  - NetDev:
      Name: br-lbaas
      Kind: bridge
  - NetDev:
      Name: br-lbaas-veth
      Kind: veth
    Peer:
      Name: eth14
{% endif %}
{% if 'ironic' in bootstrap_host_scenarios_expanded %}
  - NetDev:
      Name: dummy-bmaas
      Kind: dummy
  - NetDev:
      Name: br-bmaas
      Kind: bridge
  - NetDev:
      Name: br-bmaas-veth
      Kind: veth
    Peer:
      Name: eth15
{% endif %}

aio_systemd_networkd_networks_bootstrap:
  - interface: "dummy-mgmt"
    bridge: "br-mgmt"
    mtu: 9000
  - interface: "br-mgmt"
    config_overrides:
      Network:
        Address:
          ? {{ [bootstrap_host_management_address, mgmt_network | ansible.utils.ipaddr('prefix')] | join('/') }}
          ? {{ [bootstrap_host_internal_address, mgmt_network | ansible.utils.ipaddr('prefix')] | join('/')  }}

  - interface: "dummy-storage"
    bridge: "br-storage"
    mtu: 9000
  - interface: "br-storage"
    address: "{{ storage_network | ansible.utils.nthhost('100') }}"
    netmask: "{{ storage_network | ansible.utils.ipaddr('netmask')  }}"

  - interface: "dummy-vxlan"
    bridge: "br-vxlan"
    mtu: 9000
  - interface: "br-vxlan"
    address: "{{ vxlan_network | ansible.utils.nthhost('100') }}"
    netmask: "{{ vxlan_network | ansible.utils.ipaddr('netmask') }}"

  - interface: "dummy-vlan"
    bridge: "br-vlan"
    mtu: 9000
  - interface: "br-vlan"
    config_overrides:
      Network:
        Address:
          ? {{ vlan_network | ansible.utils.ipaddr('100') }}
          ? {{ vlan_network | ansible.utils.ipaddr('1') }}
  - interface: "br-vlan-veth"
    bridge: "br-vlan"
    mtu: 9000

{% if 'trove' in bootstrap_host_scenarios_expanded %}
  - interface: "dummy-dbaas"
    bridge: "br-dbaas"
    mtu: 9000
  - interface: "br-dbaas"
    address: "{{ dbaas_network | ansible.utils.nthhost('100') }}"
    netmask: "{{ dbaas_network | ansible.utils.ipaddr('netmask') }}"
  - interface: "br-dbaas-veth"
    bridge: "br-dbaas"
    mtu: 9000
{% endif %}
{% if 'octavia' in bootstrap_host_scenarios_expanded %}
  - interface: "dummy-lbaas"
    bridge: "br-lbaas"
    mtu: 9000
  - interface: "br-lbaas"
    address: "{{ lbaas_network | ansible.utils.nthhost('100') }}"
    netmask: "{{ lbaas_network | ansible.utils.ipaddr('netmask') }}"
  - interface: "br-lbaas-veth"
    bridge: "br-lbaas"
    mtu: 9000
{% endif %}
{% if 'ironic' in bootstrap_host_scenarios_expanded %}
  - interface: "dummy-bmaas"
    bridge: "br-bmaas"
    mtu: 1500
  - interface: "br-bmaas"
    address: "{{ bmaas_network | ansible.utils.nthhost('100') }}"
    netmask: "{{ bmaas_network | ansible.utils.ipaddr('netmask') }}"
  - interface: "br-bmaas-veth"
    bridge: "br-bmaas"
    mtu: 1500
{% endif %}

aio_systemd_services_postnetwork:
  - service_name: "networking-post-up"
    config_overrides:
      Unit:
        Description: networking-post-up
        After: network-online.target
        Wants: network-online.target
      Service:
        RemainAfterExit: true
    service_type: oneshot
    execstarts:
      - "{{ bootstrap_host_iptables_path }} -t nat -A POSTROUTING -o {{ bootstrap_host_public_interface }} -j MASQUERADE"
      - "{{ bootstrap_host_ethtool_path }} -K br-mgmt gso off sg off tso off tx off"
      - "{{ bootstrap_host_ethtool_path }} -K br-vxlan gso off sg off tso off tx off"
      - "{{ bootstrap_host_ethtool_path }} -K br-storage gso off sg off tso off tx off"
      - "{{ bootstrap_host_ethtool_path }} -K br-vlan gso off sg off tso off tx off"
      - "{{ bootstrap_host_ip_path }} link set eth12 up"
      - "{{ bootstrap_host_ip_path }} link set br-vlan-veth up"
      - "{{ bootstrap_host_ethtool_path }} -K eth12 gso off sg off tso off tx off"
{% if 'trove' in bootstrap_host_scenarios_expanded %}
      - "{{ bootstrap_host_ethtool_path }} -K br-dbaas gso off sg off tso off tx off"
      - "{{ bootstrap_host_ip_path }} link set eth13 up"
      - "{{ bootstrap_host_ip_path }} link set br-dbaas-veth up"
      - "{{ bootstrap_host_ethtool_path }} -K eth13 gso off sg off tso off tx off"
{% endif %}
{% if 'octavia' in bootstrap_host_scenarios_expanded %}
      - "{{ bootstrap_host_ethtool_path }} -K br-lbaas gso off sg off tso off tx off"
      - "{{ bootstrap_host_ip_path }} link set eth14 up"
      - "{{ bootstrap_host_ip_path }} link set br-lbaas-veth up"
      - "{{ bootstrap_host_ethtool_path }} -K eth14 gso off sg off tso off tx off"
{% endif %}
{% if 'ironic' in bootstrap_host_scenarios_expanded %}
      - "{{ bootstrap_host_ethtool_path }} -K br-bmaas gso off sg off tso off tx off"
      - "{{ bootstrap_host_ip_path }} link set eth15 up"
      - "{{ bootstrap_host_ip_path }} link set br-bmaas-veth up"
      - "{{ bootstrap_host_ethtool_path }} -K eth15 gso off sg off tso off tx off"
{% endif %}
    execstops:
      - "{{ bootstrap_host_iptables_path }} -t nat -D POSTROUTING -o {{ bootstrap_host_public_interface }} -j MASQUERADE"
    enabled: true
    state: started
